﻿package
{
	import flash.xml.*;
	import flash.events.*;
	import flash.net.*;
	
	public class UIConfiguration
	{
		//define the array to install 
		public static var uiConfig:Array = new Array();
		public static var urlLoader:URLLoader;
					
		static public function InitData()
		{
			//read from remote XML for UI layout congiguration
			var webroot:String = "file://C:\\Work\\Game\\SimLife\\";
			var urlRequest:URLRequest = new URLRequest(webroot + "Configuration\\UIConfig.xml");
			urlLoader = new URLLoader();
			
			urlLoader.load(urlRequest);
			urlLoader.addEventListener(Event.COMPLETE, onXMLComplete);
		}
		
		static function onXMLComplete(event:Event)
		{
			var myXML:XML;
			
			var uiItem:UIItem;
			
			//var loader:URLLoader = event.target;
			if (urlLoader != null)
			{
				myXML = new XML(urlLoader.data);
				
				var i:uint = 0;
				
				for each (var item:XML in myXML.item)
				{
					uiItem = new UIItem();
					uiItem.Name = item.@id;
					uiItem.X = item.@X;
					uiItem.Y = item.@Y;
					uiItem.Width = item.@Width;
					uiItem.Height = item.@Height;
					uiItem.Type = item.@Type;
					uiItem.Resource = item.@Resource;
					uiConfig.push(uiItem);
					i++;
				}//end for
				
			}//end if
		}
			
	}
}
